package cn.edu.seu.herald.informationplatform.filter;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import cn.edu.seu.herald.informationplatform.bean.league.Activity;
import cn.edu.seu.herald.informationplatform.bean.league.Linked;

public class LinkedActivityAdapter {
	
	private static final String BASE_LINK_URL = "";
	
	private static LinkedActivityAdapter _instance;
	
	public static LinkedActivityAdapter getInstance() {
		initialize();
		return _instance;
	}
	
	private static void initialize() {
		if (_instance == null) {
			_instance = new LinkedActivityAdapter();
		}
	}
	
	private static String getLinkString(int activityId) {
		return BASE_LINK_URL + activityId;
	}
	
	protected LinkedActivityAdapter() {
	}
	
	public Linked<Activity> adapt(Activity  activity, int key) {
		Linked<Activity> linked = new Linked<Activity>();
		linked.setLink(getLinkString(key));
		linked.setEntity(activity);
		return linked;
	}
	
	public List<Linked<Activity>> adapt(
			Map<Integer, Activity> activityMapping) {
		List<Linked<Activity>> adaptor =
				new LinkedList<Linked<Activity>>();
		for (Entry<Integer, Activity> entry: activityMapping.entrySet()) {
			int key = entry.getKey();
			Activity value = entry.getValue();
			Linked<Activity> linked = adapt(value, key);
			adaptor.add(linked);
		}
		return adaptor;
	}

}
